//
// Created by xbm on 23-3-10.
//

#ifndef WEBSERVER_HANDLER_H
#define WEBSERVER_HANDLER_H

#include <future>
#include <memory>
#include "event.h"
#include "concurrentQueue.h"
#include "../timer/timer.h"
#include "../util/nonCopyable.h"

namespace event {

class ResultSupervisorHandler : util::NonCopyable {
public:
    static ResultSupervisorHandler &getInstance() {
        static ResultSupervisorHandler rsh;
        return rsh;
    }

    void run();

    void close();

    static void addResult(std::future<void>);

private:
    void working();

    ResultSupervisorHandler();

    ~ResultSupervisorHandler();

    static inline util::ConcurrentQueue<std::future<void>> results_;
    bool running_ = true;
    int finished_ = 0;
    int errors_ = 0;
    int suspends_ = 0;

};


void runSelfEventHandler(std::shared_ptr<Event> e);

void socketAcceptHandler(std::shared_ptr<Event> e);

void socketReadHandler(std::shared_ptr<Event> e);

void socketWriteHandler(std::shared_ptr<Event> e);

void socketErrorHandler(std::shared_ptr<Event> e);

void socketCloseHandler(std::shared_ptr<Event> e);

void socketExpireHandler(std::shared_ptr<Event> e);


void registerHandles();


}

#endif //WEBSERVER_HANDLER_H
